#!/sbin/openrc-run

name=matrix2051
description="Matrix2051 is a Matrix gateway for IRC"

: ${command_user:="nobody:nobody"}
: ${EPMD:="/usr/bin/epmd"}

export ELIXIR_ERL_OPTIONS="${ELIXIR_ERL_OPTIONS:-"-kernel inet_dist_use_interface {127,0,0,1}"}"
export ERL_EPMD_ADDRESS="${ERL_EPMD_ADDRESS:-"127.0.0.1"}"

command="/usr/lib/matrix2051/bin/matrix2051"
command_args="start $command_args"
command_background="yes"
pidfile="/run/${RC_SVCNAME}.pid"
output_log="/var/log/matrix2051.log"
error_log="/var/log/matrix2051.log"

depend() {
	need localmount net
	after firewall
}

start_pre() {
	checkpath -f -m 0640 -o "$command_user" "$output_log" "$error_log"
}

stop_post() {
	"$EPMD" -names 2>/dev/null | grep -q '^name' || "$EPMD" -kill >/dev/null
}
